package com.newasia.server.common.checkHandler;

import com.newasia.server.common.exception.ValidateException;
import com.newasia.server.common.result.ManagementRetCode;
import com.newasia.server.controller.form.UserForm;

/**
 * @author LiChong
 * @description 电话号码检测
 * @date 2020/4/2
 */

public class MobileCheckHandler extends CheckHandler {

    @Override
    public void doHandler(UserForm form) {
        String rex = "^[1-9]\\d*$";
        String mobile = form.getMobile();
        if (!mobile.matches(rex)||!(mobile.length() == 11)) {
            throw new ValidateException(
                    ManagementRetCode.MOBILE_ERROR.getCode(),
                    ManagementRetCode.MOBILE_ERROR.getMessage());
        }
        if(null != next) {
            next.doHandler(form);
        }
    }
}
